#!/usr/local/bin/python3



# data
syncs_ratio_001_threshold_05=[0, 0, 0, 1, 2, 1, 0, 1, 0, 1, 1, 2, 0, 1, 0, 2, 0, 1, 1, 1]
syncs_ratio_001_threshold_06=[0, 0, 0, 0, 1, 2, 1, 0, 0, 1, 1, 0, 2, 0, 1, 0, 1, 0, 0, 3]
syncs_ratio_002_threshold_05=[0, 1, 3, 1, 0, 3, 1, 1, 2, 2, 0, 3, 1, 2, 1, 2, 1, 2, 1, 2]
syncs_ratio_002_threshold_06=[0, 0, 4, 0, 0, 3, 1, 0, 3, 0, 2, 1, 1, 1, 2, 0, 2, 1, 2, 1]
syncs_ratio_003_threshold_05=[1, 3, 2, 3, 1, 3, 2, 2, 2, 3, 2, 3, 1, 3, 2, 3, 3, 2, 3, 2]
syncs_ratio_003_threshold_06=[0, 4, 0, 4, 0, 4, 0, 3, 1, 3, 0, 4, 0, 3, 1, 3, 0, 4, 0, 4]
syncs_ratio_004_threshold_05=[3, 3, 4, 2, 4, 3, 3, 4, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 2, 3]
syncs_ratio_004_threshold_06=[2, 3, 1, 3, 2, 2, 2, 3, 3, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 2]


utils_ratio_001_threshold_05=[[0.13311103804319516, 0.19671636357934896, 0.16080335152107417, 0.12215185563558414], [0.23717173067143543, 0.3166333282363812, 0.32740503784611563, 0.215193169335939], [0.35545017789080297, 0.4604244963205995, 0.48649182546391495, 0.3433403835677025], [0.4469935626373997, 0.4604244963205995, 0.41946503496529297, 0.4375083297261606], [0.4763037569812828, 0.4734391863057146, 0.17114415488200838, 0.4879134074853624], [0.1385928058706237, 0.2190173288443917, 0.37923419239329864, 0.12088065928213824], [0.28669435720800973, 0.12250543722818277, 0.43666707116623155, 0.23133476629680283], [0.41589650397578726, 0.21394537621239967, 0.43444391713150743, 0.32978017701025364], [0.4813703607110508, 0.33219699698919036, 0.16442651522301435, 0.4361437529308542], [0.276360049514874, 0.47260909318988636, 0.3504064799902544, 0.49212657390722214], [0.15251787201422276, 0.47260909318988636, 0.42361436046813983, 0.24093723279232732], [0.2746828102771445, 0.3291282799493174, 0.03214504375795638, 0.12114517168100104], [0.41333229902728474, 0.10491053151966917, 0.1890260015912385, 0.23251898497487117], [0.37646531575072606, 0.23283830838041736, 0.35771706095138667, 0.34663801485737994], [0.13102674629467084, 0.3463572519903541, 0.44034797982424234, 0.47537057149065093], [0.29372191941086145, 0.46658932655316676, 0.3461406329272551, 0.42531667134069817], [0.4171731378219229, 0.46658932655316676, 0.19977646254639897, 0.11420248711030873], [0.4865792968490553, 0.27521606205883176, 0.39529247735274325, 0.2161451157495115], [0.20768640327075438, 0.10181396951497798, 0.4979679766853712, 0.31633094961906116], [0.15938720847519672, 0.21048828942837025, 0.3847041071728292, 0.4393866430545204]]
utils_ratio_001_threshold_06=[[0.17591098542600114, 0.18231754116980198, 0.1342663868994291, 0.1162244155791375], [0.28910926550102384, 0.33586051884874074, 0.3147664242763079, 0.20663290330344083], [0.3919607938926394, 0.4956916816821558, 0.5083113469995946, 0.3176972627965701], [0.49211110894550353, 0.4956916816821558, 0.5196285089329966, 0.4232131393618729], [0.5888485231503627, 0.5006005347109664, 0.3349531321692441, 0.5286268722980516], [0.3624651983073437, 0.2165966551293757, 0.1564063665927369, 0.5879369895514698], [0.14322394595038487, 0.0960823137435193, 0.31987345768924913, 0.46520655129134725], [0.3010394606508615, 0.2145396573551744, 0.4768103605954754, 0.11010874452054677], [0.4700058199125802, 0.3290347957871598, 0.5019116682236096, 0.21971948325255786], [0.5172935572144113, 0.45324660565668884, 0.30217630660676614, 0.3318686200736057], [0.2943039612047121, 0.5708602991867736, 0.1808918248738486, 0.4422533874264089], [0.14922158142540196, 0.5708602991867736, 0.35981461668639414, 0.5660167830951305], [0.29380041942452784, 0.45673735641554536, 0.5372004604850755, 0.2742962408016045], [0.41687126296466503, 0.1285583569704752, 0.5640490094391891, 0.12194336535433221], [0.5542945277896731, 0.24073081332800578, 0.24491281476527813, 0.22076117056180636], [0.5884236261973774, 0.3539406683334416, 0.1884211447322367, 0.3307859005684609], [0.3844317200813715, 0.4736725982988637, 0.35085509961010775, 0.45962612890921667], [0.13127639934196422, 0.591021236619552, 0.540793615566737, 0.559898700840268], [0.29581615232191416, 0.591021236619552, 0.540793615566737, 0.583866134372802], [0.44171730137322496, 0.3549183232650148, 0.04424088709218661, 0.2918148549513873]]
utils_ratio_002_threshold_05=[[0.2979822491922277, 0.39661295588455914, 0.33986427430673577, 0.2263174309999071], [0.47460877650686084, 0.4346287259289039, 0.263432808124911, 0.43336542063900946], [0.4563260898638501, 0.2267529003767505, 0.36987070750181317, 0.39652984375802686], [0.2764697907000441, 0.20959105923016746, 0.2711226407590836, 0.23213895840727847], [0.4735901480984461, 0.42001779623751206, 0.3793290541678411, 0.4721005524988803], [0.45302959998665693, 0.4695442039177481, 0.10641461839492268, 0.26200797064970877], [0.28527119350242464, 0.3372167296741594, 0.3847544011152545, 0.2290447128653809], [0.48301430552559077, 0.25016311859192947, 0.3840505711522604, 0.46176549109432186], [0.36918167675971697, 0.42368316016691837, 0.3301031639201188, 0.39527941530168287], [0.32247697612467247, 0.3234716469858871, 0.08331901197911722, 0.23064835648677634], [0.4677473179825251, 0.2449745356632344, 0.3731555582875916, 0.4560638300961307], [0.3166270477310188, 0.47100156358929657, 0.09451121305509284, 0.2620956984246807], [0.28214812010372364, 0.4341262298830399, 0.3510968082120682, 0.22197402847431105], [0.3722985448973789, 0.22981881135195362, 0.09616351830542558, 0.46911262562456435], [0.31740312114453206, 0.49179792937395295, 0.40651108837394145, 0.3470582018989028], [0.4751545864585587, 0.4232385946151734, 0.10061291624832101, 0.22230384012501378], [0.2950912981174169, 0.22103100145153048, 0.4550064242510277, 0.4570597976105635], [0.2951506137887763, 0.4701663076019554, 0.47540220171155756, 0.34792472141478836], [0.47012098332601676, 0.41780114114086553, 0.3473813744127003, 0.23584170205830635], [0.3795588650346182, 0.2211381211196325, 0.024059486856526317, 0.4539519441623002]]
utils_ratio_002_threshold_06=[[0.2793389098495902, 0.38256345269514574, 0.31486204228561093, 0.20457700320324052], [0.47987741364463854, 0.4156932892328244, 0.5352802940164207, 0.4463190085628804], [0.2503180612358369, 0.23015362682045176, 0.4376122859852123, 0.22702456603715684], [0.29174306037808895, 0.20336095617804972, 0.32458886655763336, 0.27517512886890544], [0.5720836787184551, 0.4372787009962239, 0.5643831644020623, 0.4937531912880481], [0.25321746150225616, 0.5153236737205916, 0.11626446689840349, 0.3446477999407185], [0.2801550777554032, 0.2557751876421827, 0.43777954389525114, 0.23665551951219602], [0.5823220152728, 0.2148518075620256, 0.5923154896084758, 0.48469491787287644], [0.4261258806343524, 0.4508324878286167, 0.13389287396883462, 0.2083495339943855], [0.31158404008137663, 0.5234600890947675, 0.41752232050897425, 0.23201086518880018], [0.5587287417708893, 0.3020793107207419, 0.019653601126888257, 0.41474636363974765], [0.293837849760464, 0.20928177934797323, 0.38504699110276536, 0.5842963056954863], [0.31739335640434874, 0.45289925551698534, 0.5573622438450182, 0.33997188528582073], [0.5732178358700987, 0.5203034531776378, 0.46833480062960764, 0.20698171824986766], [0.3706956853718753, 0.4015773045832016, 0.3830780579115786, 0.42558852283867954], [0.28541963805952986, 0.19757605356750726, 0.5270179848330877, 0.5978312459840758], [0.5478562614359161, 0.40663832583376336, 0.2065658369295887, 0.3093445634454659], [0.4931244740317694, 0.5548513628404735, 0.3768748873311741, 0.2684758471263851], [0.3109439773567541, 0.33686706844388004, 0.02243189925052444, 0.5158505472352678], [0.5471519413414623, 0.2292147519645436, 0.2927925190828109, 0.21730934411398603]]
utils_ratio_003_threshold_05=[[0.4482478039776423, 0.4423447121537405, 0.448305718096257, 0.30365079975456954], [0.34078161383782113, 0.3980046191199729, 0.11355234705830873, 0.48925712595084875], [0.43529202336055856, 0.3836908134628545, 0.18564094613526155, 0.3814930264215232], [0.28457849674499136, 0.2944050669498398, 0.17523055842475194, 0.32159726628794566], [0.4799383595415564, 0.2553926563445641, 0.4227955790301496, 0.3710430737865125], [0.39058532601558626, 0.3219032026008914, 0.11968703807492508, 0.2666254454070057], [0.4602284451836333, 0.34929003991391705, 0.13268219494632078, 0.4158083069101736], [0.22669948373093038, 0.3831245723129943, 0.48700815018940635, 0.43905111650706535], [0.4595314639199401, 0.3511843592961802, 0.1634763119059168, 0.3511058684462361], [0.32292954804674256, 0.3208578665289147, 0.19240424670878076, 0.2841524132641516], [0.3803894877468216, 0.29645490765504884, 0.11481417018469622, 0.33134252001878584], [0.3877414659368279, 0.3270988595464255, 0.17350528675543989, 0.4836924260188737], [0.4782034848561721, 0.43288130992240204, 0.48510079046596544, 0.36495136187357846], [0.23242798070872292, 0.31100529840850555, 0.15358634185757397, 0.37693338394870585], [0.46353996108237716, 0.27050268447317, 0.11804950993763595, 0.32138377826111436], [0.20745001529553247, 0.3163925722667162, 0.09659079786996662, 0.4494733642858332], [0.3984700290787116, 0.3039957942115735, 0.0868391478496279, 0.3855162691563376], [0.4479760798033094, 0.33287312441128164, 0.4992760981299642, 0.3077448134545172], [0.33398127589539406, 0.47957937494490854, 0.26450649982125707, 0.3334644991869081], [0.49333684803182043, 0.44255206568327865, 0.21982386301644183, 0.415380421899311]]
utils_ratio_003_threshold_06=[[0.42228346916556136, 0.5376462803779498, 0.5397892322658957, 0.355330497805345], [0.24830900448111845, 0.26369886705061363, 0.49651935882302867, 0.4740484160630393], [0.45943937119870437, 0.3331988027871088, 0.4848810476876658, 0.4090784283641436], [0.3340266580996609, 0.272689584554296, 0.4546208487452398, 0.346789168912887], [0.4855927754999977, 0.3837361838020959, 0.5664773954554391, 0.3448512547926027], [0.3409390681158214, 0.27604600029388837, 0.4396752627801579, 0.43293551872932756], [0.5211505287858361, 0.3039125283362546, 0.4968039460921926, 0.3254928318549664], [0.22948127898558843, 0.5923941553414098, 0.16522058304682719, 0.32393194866484565], [0.42648178037069306, 0.4557896232833125, 0.5754431281488067, 0.3752770005072346], [0.41150009125632914, 0.3373646104851616, 0.17845973943752616, 0.2680661271118072], [0.44847702050672567, 0.5251869879927261, 0.5905750478408472, 0.4060730650044235], [0.2852757100625876, 0.4317795770202085, 0.47670198704215516, 0.3097667551789869], [0.4439901573525509, 0.3524779758207737, 0.5893339557376793, 0.33231483942892937], [0.34869506788010646, 0.4903552692542164, 0.1530651314717038, 0.47769712672688086], [0.4690910789686967, 0.36342657671121836, 0.5976822060126769, 0.3852878102950548], [0.4505004673717535, 0.3087989764000535, 0.12543722108164823, 0.27165664448352245], [0.4393664169147853, 0.5691933424068297, 0.5739893664849894, 0.4038200879125069], [0.3051596463408409, 0.40186389951660534, 0.26560416967791567, 0.3967337801181299], [0.5041269918197597, 0.3434557893566285, 0.565308520483213, 0.334399660017019], [0.41695569066485205, 0.4263161954248183, 0.3014392914145183, 0.2162274803083005]]
utils_ratio_004_threshold_05=[[0.38350603338917677, 0.28398190430736553, 0.36568611889353075, 0.42855521658296036], [0.21416302693857017, 0.48763956673932685, 0.191384057928808, 0.2424119500684701], [0.3883682587491046, 0.4921517296878853, 0.2853346299869052, 0.4612032100019363], [0.2763223480125928, 0.43041405511668607, 0.21405055874269296, 0.47689281867094924], [0.38102349774565136, 0.24763503174558127, 0.3151557313107053, 0.2635612330686437], [0.3273168568994067, 0.42220005448760656, 0.16195146345661232, 0.43652926325143804], [0.4322184781142995, 0.24737892982247522, 0.3322372133656195, 0.4407940272805612], [0.30407409083976517, 0.4471691575150387, 0.31781195333888507, 0.21964171765593876], [0.26883500507315133, 0.470625856595014, 0.22905171810942787, 0.227886711792198], [0.43948755081375485, 0.25145186766658306, 0.3530897715281175, 0.4955586949481291], [0.2647220157601202, 0.46293723202050013, 0.19810424108703703, 0.46441081042820875], [0.2927940174240722, 0.43795956089073795, 0.46624981767768586, 0.45860883150093834], [0.23877324066260977, 0.40727909502235343, 0.12382093588694913, 0.35561636993847795], [0.417268452530865, 0.2766036272287959, 0.27832146056979024, 0.4666483889280563], [0.4931738528735704, 0.4336755151635759, 0.21382493384980084, 0.4250166600687745], [0.33040954284821755, 0.24019900131004715, 0.30923492973073846, 0.4789899398512515], [0.43852093182485674, 0.458885612742938, 0.18043376487956495, 0.4171492537732286], [0.3539849654951845, 0.2635288033028469, 0.39431132160852467, 0.48165002305338606], [0.4857883009539654, 0.45966242772635363, 0.4287727035405087, 0.44898333932383677], [0.22184662339346609, 0.23540678310557078, 0.24392635320010583, 0.42458989860458746]]
utils_ratio_004_threshold_06=[[0.46753110714718793, 0.3328852599856536, 0.03550564296199268, 0.4618364450931503], [0.4772205572378963, 0.539664834317819, 0.2011411197249488, 0.2974999456388665], [0.570370573328162, 0.3921901095427285, 0.5795406145747727, 0.42464625437553594], [0.36656563303525835, 0.4322656207320823, 0.15155995828538976, 0.4231759586000142], [0.5522800504225721, 0.2661346593883605, 0.20433524602769057, 0.46036059000287016], [0.356197885878199, 0.45363844926649893, 0.5779347576682484, 0.23873938442910325], [0.5655466333025757, 0.23065995657752192, 0.16936793918566845, 0.4658125404583756], [0.40662162525103607, 0.4713180172012777, 0.1421580386503928, 0.302044741288404], [0.4720447651195106, 0.27142243126540777, 0.34415435108414527, 0.45296188969960177], [0.5845299540422635, 0.49876289044946615, 0.23062579427548446, 0.376874026049293], [0.3866834280799799, 0.48099311640934833, 0.49706709196334187, 0.47250455194358704], [0.5993101702458546, 0.4919905205749806, 0.26213907302024125, 0.33476721234088236], [0.47616345462309273, 0.2447204691470483, 0.4287580506267371, 0.4875794851681374], [0.5814886263356257, 0.5834354707120026, 0.48891837296028473, 0.3770119457834724], [0.3917247548801168, 0.31871357387446925, 0.5811018523462422, 0.4600481677516805], [0.5671364568229645, 0.4838581634753016, 0.4174616450319134, 0.2875612985241398], [0.37979685649117967, 0.44770369192202153, 0.34686423674238365, 0.5195883763636205], [0.5772509488783597, 0.46631072967366444, 0.22990693875177817, 0.3294839829840012], [0.28770964748031674, 0.482671444248422, 0.3851927521175813, 0.4456796471201815], [0.513121168606742, 0.500560035196715, 0.36078656619655414, 0.42640793748758493]]


# compose data
ratio_var_util_t05 = [[max(utils_ratio_001_threshold_05[i]) for i in range(len(utils_ratio_001_threshold_05))], [max(utils_ratio_002_threshold_05[i]) for i in range(len(utils_ratio_002_threshold_05))], [max(utils_ratio_003_threshold_05[i]) for i in range(len(utils_ratio_003_threshold_05))], [max(utils_ratio_004_threshold_05[i]) for i in range(len(utils_ratio_004_threshold_05))]]
ratio_var_util_t06 = [[max(utils_ratio_001_threshold_06[i]) for i in range(len(utils_ratio_001_threshold_06))], [max(utils_ratio_002_threshold_06[i]) for i in range(len(utils_ratio_002_threshold_06))], [max(utils_ratio_003_threshold_06[i]) for i in range(len(utils_ratio_003_threshold_06))], [max(utils_ratio_004_threshold_06[i]) for i in range(len(utils_ratio_004_threshold_06))]]

thre_var_util_r001 = [[max(utils_ratio_001_threshold_05[i]) for i in range(len(utils_ratio_001_threshold_05))], [max(utils_ratio_001_threshold_06[i]) for i in range(len(utils_ratio_001_threshold_06))]]
thre_var_util_r002 = [[max(utils_ratio_002_threshold_05[i]) for i in range(len(utils_ratio_002_threshold_05))], [max(utils_ratio_002_threshold_06[i]) for i in range(len(utils_ratio_002_threshold_06))]]
thre_var_util_r003 = [[max(utils_ratio_003_threshold_05[i]) for i in range(len(utils_ratio_003_threshold_05))], [max(utils_ratio_003_threshold_06[i]) for i in range(len(utils_ratio_003_threshold_06))]]
thre_var_util_r004 = [[max(utils_ratio_004_threshold_05[i]) for i in range(len(utils_ratio_004_threshold_05))], [max(utils_ratio_004_threshold_06[i]) for i in range(len(utils_ratio_004_threshold_06))]]

ratio_var_sync_t05 = [syncs_ratio_001_threshold_05, syncs_ratio_002_threshold_05, syncs_ratio_003_threshold_05, syncs_ratio_004_threshold_05]
ratio_var_sync_t06 = [syncs_ratio_001_threshold_06, syncs_ratio_002_threshold_06, syncs_ratio_003_threshold_06, syncs_ratio_004_threshold_06]

thre_var_sync_r001 = [syncs_ratio_001_threshold_05, syncs_ratio_001_threshold_06]
thre_var_sync_r002 = [syncs_ratio_002_threshold_05, syncs_ratio_002_threshold_06]
thre_var_sync_r003 = [syncs_ratio_003_threshold_05, syncs_ratio_003_threshold_06]
thre_var_sync_r004 = [syncs_ratio_004_threshold_05, syncs_ratio_004_threshold_06]



import matplotlib
matplotlib.rcParams['ps.useafm'] = True
matplotlib.rcParams['pdf.use14corefonts'] = True
matplotlib.rcParams['text.usetex'] = True

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import ticker
from matplotlib.ticker import FuncFormatter, MultipleLocator
import os
import matplotlib.pylab as pylab

from matplotlib.ticker import FormatStrFormatter

COLORS = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
          '#9467bd', '#8c564b', '#e377c2', '#7f7f7f',
          '#bcbd22', '#17becf']

font_size = '12'
params = {
    'axes.labelsize' : font_size,
    'xtick.labelsize' : font_size,
    'ytick.labelsize' : font_size,
    # 'lines.linewidth' : '0.2',
    'legend.fontsize' : font_size,
    'figure.figsize' : '4, 2.8',
}
pylab.rcParams.update(params)




def plot_bar(data, xticks, xlabel, ylabel, filename):

    plt.close('all')
    plt.figure()

    x_pos = np.arange(1, len(data) + 1)
    xticks = x_pos
    # for i in range(len(data)):
    plt.bar(x_pos, data, color=COLORS[0])

    
    # plt.xticks(x_pos, xticks)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.tight_layout(True)

    filename = filename
    
    plt.savefig('{}.pdf'.format(filename), format='pdf', dpi=900)
    # plt.show()

# ratio001 thresh05 06
plot_bar(np.multiply(thre_var_util_r001[0], 100.0), '', 'Epoch', 'Maximum link utilization (\%)', 'thre_05_util_r001')
plot_bar(np.multiply(thre_var_util_r001[1], 100.0), '', 'Epoch', 'Maximum link utilization (\%)', 'thre_06_util_r001')

# ratio002 thresh05 06
plot_bar(np.multiply(thre_var_util_r002[0], 100.0), '', 'Epoch', 'Maximum link utilization (\%)', 'thre_05_util_r002')
plot_bar(np.multiply(thre_var_util_r002[1], 100.0), '', 'Epoch', 'Maximum link utilization (\%)', 'thre_06_util_r002')

# ratio003 thresh05 06
plot_bar(np.multiply(thre_var_util_r003[0], 100.0), '', 'Epoch', 'Maximum link utilization (\%)', 'thre_05_util_r003')
plot_bar(np.multiply(thre_var_util_r003[1], 100.0), '', 'Epoch', 'Maximum link utilization (\%)', 'thre_06_util_r003')

# ratio004 thresh05 06
plot_bar(np.multiply(thre_var_util_r004[0], 100.0), '', 'Epoch', 'Maximum link utilization (\%)', 'thre_05_util_r004')
plot_bar(np.multiply(thre_var_util_r004[1], 100.0), '', 'Epoch', 'Maximum link utilization (\%)', 'thre_06_util_r004')

